<template>
    <div class="app-container">
        <el-form class="lookForm" :model="queryParams" ref="queryForm" size="mini" :inline="true" label-width="140px">
            <el-form-item label="学号" prop="stuNo">
                <el-input v-model="queryParams.stuNo" placeholder="请输入学号" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="学生姓名" prop="stuName">
                <el-input v-model="queryParams.stuName" placeholder="请输入学生姓名" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="岗位名称" prop="postName">
                <el-input v-model="queryParams.postName" placeholder="请输入岗位名称" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="工作日期" prop="workDate">
                <el-date-picker clearable v-model="queryParams.workDate" type="date" value-format="yyyy-MM-dd"
                    placeholder="请选择工作日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="审核状态" prop="applyStatus">
                <el-select v-model="queryParams.applyStatus" placeholder="请选择审核状态" clearable>
                    <el-option v-for="dict in dict.type.qgzx_stu_post_status" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="tableData">
            <el-table-column label="学号" align="center" prop="stuNo" />

            <el-table-column label="姓名" align="center" prop="stuName" />
            <el-table-column label="学院" align="center" prop="stuDept" />

            <el-table-column label="岗位名称" align="center" prop="postName" />
            <el-table-column label="岗位类型" align="center" prop="postType" />
            <el-table-column label="设岗部门" align="center" prop="deptName" />
            <el-table-column label="工作日期" align="center" prop="workDate" />

            <el-table-column label="工作时长" align="center">
                <template v-slot="{ row }">
                    {{ row.postType == "固定岗位A" ? row.workTime + "天" : row.workTime + "小时" }}
                </template>
            </el-table-column>


            <el-table-column label="审核状态" align="center" prop="applyStatus">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.qgzx_stu_post_status" :value="scope.row.applyStatus" />
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-view" @click="lookVClick(scope.row)">查看</el-button>
                </template>
            </el-table-column>
        </el-table>



        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />



        <el-dialog title="审核" :visible.sync="lookV" append-to-body>
            <el-form class="lookForm" size="mini" ref="applyForm" label-width="148px">
                <el-form-item label="工作岗位">
                    <el-input v-model="lookForm.postName" readonly />
                </el-form-item>

                <el-form-item label="主要工作">
                    <el-input v-model="lookForm.mainWork" type="textarea" readonly />
                </el-form-item>
                <el-form-item label="工作附件">
                    <ImagePreview :src="lookForm.workMaterial" />
                </el-form-item>
                <el-form-item label="工作日期">
                    <el-input v-model="lookForm.workDate" readonly />
                </el-form-item>
                <el-form-item label="工作时长">
                    <el-input v-model="lookForm.workTime" type="number" readonly />
                    {{ lookForm.postType == "固定岗位A" ? "天" : "小时" }}
                </el-form-item>
                <el-form-item label="审核意见">
                    <el-radio-group v-model="lookForm.zdlsCmt" disabled>
                        <el-radio :label="'通过'">通过</el-radio>
                        <el-radio :label="'不通过'">不通过</el-radio>
                    </el-radio-group>
                </el-form-item>

                <el-form-item label="指导老师签章">
                    <img v-if="lookForm.zdlsSign" :src="baseurl + lookForm.zdlsSign" width="200px" height="50px"
                        class="avatar">
                </el-form-item>
            </el-form>


        </el-dialog>

    </div>
</template>
<script>

import { getOwnSign } from "@/api/workstudy/post";
import { doAudit, listZdlsAll as getList } from "@/api/workstudy/worklog";

import { CheckImgExists, fullLoading, isEmpty } from "@/api/helpFunc";
import { getToken } from "@/utils/auth";

export default {
    name: "workstudy-StuPost-zdls",
    dicts: ['qgzx_stu_post_status'],
    data() {
        return {
            isEmpty,
            loading: false,

            tableData: [],
            total: 0,
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                postName: null
            },


            editV: false,
            lookForm: {},
            applyForm: {},

            upload: {
                headers: { Authorization: "Bearer " + getToken() },
                // 上传的地址
                url: process.env.VUE_APP_BASE_API + "/common/upload"
            },
            baseurl: process.env.VUE_APP_BASE_API + "/",

            lookV: false,

            auditForm: {
                id: null,
                zdlsCmt: null,
                zdlsSign: null
            },
        }
    },
    created() {
        this.getList();
    },
    methods: {
        async doAudit() {
            let sdata = { ...this.auditForm };
            if (isEmpty(sdata.zdlsCmt)) {
                this.$message.info("请选择是否通过");
                return;
            }

            if (isEmpty(sdata.zdlsSign)) {
                this.$message.info("请上传签章");
                return;
            }

            if (!CheckImgExists(this.baseurl + sdata.zdlsSign)) {
                this.$message.info("签名失效，请重新上传");
                return;
            }

            let loading = fullLoading(this);
            let res = await doAudit(sdata);
            loading.close();
            if (res.code == 200) {
                this.$message.success(res.msg);
                this.getList();
                this.lookV = false;
            }


        },
        async lookVClick(row) {

            let loading1 = fullLoading(this);
            let res1 = await getOwnSign();
            loading1.close();
            if (res1.code == 200) {
                let data = { ...res1.data };
                if (isEmpty(data.signature)) {
                    this.$confirm('您的签名尚未上传', '提示', {
                        confirmButtonText: '点我前往',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.$router.push("/user/profile")
                    }).catch(() => {

                    });
                } else {
                    this.lookForm = {};
                    this.lookForm = { ...row };
                    this.auditForm.id = this.lookForm.id;
                    this.auditForm.zdlsSign = data.signature;
                    this.lookV = true;
                }
            }

        },


        handleAvatarSuccess(response, file, fileList) {
            this.auditForm.zdlsSign = response.fileName;
            this.$forceUpdate();
        },


        async getList() {
            this.loading = true;
            let res = await getList(this.queryParams);
            this.loading = false;
            if (res.code == 200) {
                this.tableData = [...res.rows];
                this.total = res.total;
            }
        },
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
    }
}



</script>


<style scoped lang="scss">
.lookForm {
    .el-form-item {
        margin-bottom: 5px;
    }
}
</style>